//树状数组 - 逆序对个数
#include <iostream>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define lowbit(x) (x & -x)
int n;
const int N = 5e5 + 10;
int a[N], t[N];

ll s[N]; //树状数组, 每个元素维护的是某个区间所有数出现的次数

void modify(int x, int k)
{
    for(int i = x; i <= n; i += lowbit(i)) s[i] += k;
}

ll query(int x)
{
    ll sum = 0;
    for(int i = x; i; i -= lowbit(i)) sum += s[i];
    return sum;
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        t[i] = a[i];
    }

    //离散化
    sort(t + 1, t + 1 + n);
    int cnt = 0;
    unordered_map<int, int> mp;
    for(int i = 1; i <= n; i++)
    {
        int x = t[i];
        if(mp[x]) continue;
        mp[x] = ++cnt;
    }

    ll ret = 0;
    for(int i = 1; i <= n; i++)
    {
        int x = mp[a[i]];
        //找[x+1, cnt]之间的数一共出现了多少次
        ret += query(cnt) - query(x); //[1, cnt]之间数的次数 - [1, x]之间数的次数
        modify(x, 1);
    }
    cout << ret << endl;
    return 0;
}